<!--
 * @Descripttion: 
 * @version: 
 * @Author: 夜殇
 * @Date: 2020-07-08 08:52:10
 * @LastEditors: 夜殇
 * @LastEditTime: 2020-07-12 10:32:40
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>文件读取</title>
  </head>
  <body>
    <input type="file" id="file" />
    <script>
      const inp = document.getElementById('file')
      inp.addEventListener('change', e => {
        file = e.target.files[0]
        const read = new FileReader()
        // 开始读取文件
        read.readAsText(file)
        read.onload = function (e) {
          console.log(read.result)
        }
      })
    </script>
  </body>
</html>
